import request from "./requset";

// 订单
export const getOrderList = () =>
  request({
    url: "/api/v1/order",
    method: "get"
  });

// 会员
export const getVipList = () =>
  request({
    url: "/api/v1/vip",
    method: "get"
  });

// 库存
export const getWareList = () =>
  request({
    url: "/api/v1/ware",
    method: "get"
  });

// 商品
export const getGoodsList = () =>
  request({
    url: "/api/v1/goods",
    method: "get"
  });

export const updateGoods = goodsInfo =>
  request({
    url: "/api/v1/goods/" + goodsInfo.goods_id,
    method: "post",
    data: goodsInfo
  });

export const addGoods = goodsInfo =>
  request({
    url: "/api/v1/goods",
    method: "post",
    data: goodsInfo
  });

export const deleteGoods = goodsInfo =>
  request({
    url: "/api/v1/goods/" + goodsInfo.goods_id,
    method: "post",
    data: goodsInfo
  });

// 上传商品图片
export const saveFile = file => {
  const formData = new FormData();
  // 无法直接获得内容，要使用get
  formData.append("file", file);
  // console.log(formData.get('file'))
  return request({
    url: "/api/v1/goods",
    method: "post",
    data: formData
  });
};

// 促销活动
export const getSaleList = () =>
  request({
    url: "/api/v1/sale",
    method: "get"
  });

export const updateSale = saleInfo =>
  request({
    url: "/api/v1/sale/" + saleInfo.sale_id,
    method: "post",
    data: saleInfo
  });

export const addSale = saleInfo =>
  request({
    url: "/api/v1/sale",
    method: "post",
    data: saleInfo
  });

export const deleteSale = saleInfo =>
  request({
    url: "/api/v1/sale/" + saleInfo.sale_id,
    method: "post",
    data: saleInfo
  });
